﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using MvcContrib.EnumerableExtensions;
using QDT.Common;
using QDT.Core.Deals;
using QDT.Core.Members;
using QDT.Core.Orders;
using QDT.MVC.Security;
using QDT.P2B.Activity;
using QDT.Web.Code;

namespace QDT.Web.Controllers
{

    public class ActivityController : BaseController
    {

        public ActionResult Turntable()
        {
            var ps = DbProvider.D<UserPrize>().OrderByDescending(x=>x.ID).ToPagedList(0, 50);
            return View(ps);
        }

        public ActionResult ChouJiang()
        {
            try
            {
                var user = QDTContext.Current.User;
                if (user == null) return Json(-3);
                
                var time = new DateTime(2014, 10, 21);

                var hasCredit = DbProvider.D<Credit>().Any(x => x.UserID == user.ID && x.CreateTime > time&&x.AssignmentID==0);
                if (!hasCredit) return Json(-2);

                var isOperat = DbProvider.D<UserPrize>().Any(x => x.UserId == user.ID);
                if (isOperat) return Json(-1);
                

                var prize = new PrizeBuilder().Prize();
                if (prize==null) throw new Exception();

                var userPrize = new UserPrize()
                {
                    UserId = user.ID,
                    UserName = user.UserName,
                    PrizeId = prize.Id,
                    PrizeName = prize.Name
                };
                DbProvider.Add(userPrize);
                DbProvider.SaveChanges();

                return Json(prize, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return Json(-9999);
            }
        }

        public ActionResult LiuSpeech()
        {
            return View();
        }

        public ActionResult RecommendScoreTJ()
        {
            return View();
        }

        public ActionResult Inspect()
        {
            return View();
        }

        public ActionResult InspectLette_1()
        {
            return View();
        }
        public ActionResult InspectLette_2()
        {
            return View();
        }
        public ActionResult InspectLette_3()
        {
            return View();
        }
        public ActionResult InspectLette_4()
        {
            return View();
        }
        public ActionResult InspectLette_5()
        {
            return View();
        }
        public ActionResult InspectLette_6()
        {
            return View();
        }

        public ActionResult AwardList()
        {
            return View();
        }
    }
}
